import os
import rtconfig
from building import *

Import('SDK_LIB')

cwd = GetCurrentDir()

# add general drivers
src = Split('''
board.c
board_config.c
''')

if GetDepend(['BSP_USING_TCA9539']):
    src += Glob('ports/tca9539.c')

if GetDepend(['BSP_USING_ON_CHIP_FLASH']):
    src += Glob('ports/bl_flash.c')

src += Glob('ports/cdcacm/*.c')

path =  [cwd]
path += [cwd + '/ports']
path += [cwd + '/config']
path += [cwd + '/ports/cdcacm']
path += [cwd + '/../libraries/hc32_usb_lib/']
path += [cwd + '/../libraries/hc32_usb_lib/usb_device_lib/device_core']
path += [cwd + '/../libraries/hc32_usb_lib/usb_device_lib/device_class/single_cdc']
path += [cwd + '/../../common']
path += [SDK_LIB + 'hc32f4a0_ddl/drivers/hc32_ll_driver/inc']

if GetDepend(['RT_USING_FAL']):
    path += [cwd + '/ports/fal']

startup_path_prefix = SDK_LIB

if rtconfig.PLATFORM in ['gcc']:
    src += [startup_path_prefix + '/hc32f4a0_ddl/drivers/cmsis/Device/HDSC/hc32f4xx/Source/GCC/startup_hc32f4a0.S']
elif rtconfig.PLATFORM in ['armcc', 'armclang']:
    src += [startup_path_prefix + '/hc32f4a0_ddl/drivers/cmsis/Device/HDSC/hc32f4xx/Source/ARM/startup_hc32f4a0.s']
elif rtconfig.PLATFORM in ['iccarm']:
    src += [startup_path_prefix + '/hc32f4a0_ddl/drivers/cmsis/Device/HDSC/hc32f4xx/Source/IAR/startup_hc32f4a0.s']

CPPDEFINES = ['HC32F4A0']
CPPDEFINES += ['XTAL_VALUE = 24000000UL']

group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)

Return('group')
